const protobuf = require("protobufjs");

const root = protobuf.loadSync('protos/Stickers.proto');
const StickerPack = root.lookupType("signalservice.StickerPack");

// 创建Sticker
function Sticker(id, emoji) {
    const sticker = StickerPack.Sticker.create({
        id: id,
        emoji: emoji
    });
    return sticker;
}

// 解码Sticker包
function DecodeStickerPack(data) {
    return StickerPack.decode(data);
}

// 编码Sticker包
function EncodeStickerPack(title, author, stickers) {
    const stickerPack = StickerPack.create({
        title: title,
        author: author,
        cover: stickers[0],
        stickers: stickers
    });
    return StickerPack.encode(stickerPack).finish();
}

module.exports = { Sticker, DecodeStickerPack, EncodeStickerPack };
